import { Player } from "../player";
import {  MotionMode } from "../physics/player-physics";
import { Vector2 } from "../vector";
import { Action } from "./action-manager";
import "../ZzFX.micro";
export declare var zzfx: any;

// src/actions/spin-attack.ts  
export class SpinAttackAction implements Action {  
  name = 'spin-attack';  
  duration = 1000; // 1秒  
  startTime = 0;  
  isActive = false;  
    
  onStart(player: Player) {  
    player.physics.mode_ = MotionMode.attacking;  
    // 播放音效  
    zzfx(0.8, 0.5, 200, 0.1, 0.3, 2, 1, 0, 0.2);  
    // 发射粒子  
    player.engine.particles.emit({  
      count: 50,  
      direction_: new Vector2(3, 0),  
      lifetime: 200,  
      pos: player.body_.pos,  
    });  
  }  
    
  update(player: Player, elapsed: number) {  
    const spinAngle = (elapsed / 10) % (Math.PI * 2);  
    player.animation_.rArmRot = 1.5 + Math.cos(spinAngle) * 0.8;  
    player.animation_.lArmRot = -1.5 + Math.sin(spinAngle) * 0.8;  
    player.animation_.headOffset = Math.sin(spinAngle * 2) * 2;  
    player.animation_.scale_ = 1.1;  
      
    // 攻击时减少移动速度  
    player.body_.vel.x *= 0.3;  
  }  
    
  onEnd(player: Player) {  
    player.physics.mode_ = MotionMode.falling;  
    // 重置动画状态  
    player.animation_.scale_ = 1;  
  }  
}  
  
// src/actions/punch-attack.ts  
export class PunchAttackAction implements Action {  
  name = 'punch-attack';  
  duration = 500;  
  startTime = 0;  
  isActive = false;  
    
  onStart(player: Player) {  
    player.physics.mode_ = MotionMode.attacking;  
    zzfx(0.6, 0.3, 150, 0.1, 0.2, 1, 1, 0, 0.1);  
  }  
    
  update(player: Player, elapsed: number) {  
    const progress = elapsed / this.duration;  
    player.animation_.rArmRot = -2.5 + Math.sin(progress * Math.PI) * 0.5;  
    player.animation_.lArmRot = -0.5;  
    player.animation_.headOffset = -1;  
    player.animation_.scale_ = 1.1;  
  }  
    
  onEnd(player: Player) {  
    player.physics.mode_ = MotionMode.falling;  
    player.animation_.scale_ = 1;  
  }  
}